package org.zuel.boot.demo.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import org.zuel.boot.demo.entity.Company;
import org.zuel.boot.demo.entity.SysUser;
import org.zuel.boot.demo.service.ICompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.zuel.boot.demo.service.impl.SessionService;
import org.zuel.boot.demo.web.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 *  控制器
 *
 * @author ikun
 */
@Api(tags = "管理")
@RestController
@RequestMapping("/zuel")
public class CompanyController{
    @Autowired
    private SessionService sessionService;
    @Autowired
    private ICompanyService companyService;

    @ApiOperation("查询公司列表")
    @GetMapping("/company/list")
    public IPage<Company> list(HttpServletRequest request) {
        PageParam<Company> pageParam = new PageParam<>(request);
        return companyService.list(pageParam);
    }

    @ApiOperation("查询单个")
    @GetMapping("/company/get/{id}")
    public JsonResult read(@PathVariable("id") Integer id) {
        return companyService.read(id);
    }

    @ApiOperation("查询单个")
    @GetMapping("/company/getRandom")
    public JsonResult readRandom(HttpServletRequest request) {
        SysUser user = sessionService.validateSession1(request);
        return companyService.readRandom(user);
    }

    @ApiOperation("添加")
    @PostMapping("/company/add")
    public JsonResult add(@RequestBody Company model) {
    return companyService.add(model);
    }

    @ApiOperation("修改")
    @PostMapping("/company/update")
    public JsonResult update(@RequestBody Company model) {
    return companyService.update(model);
    }

    @ApiOperation("删除")
    @GetMapping("/company/delete/{ids}")
    public JsonResult delete(@PathVariable("ids") Integer[] ids) {
        return companyService.delete(ids);
    }

}